package core2.ch02xml;

import java.io.*;
import org.jdom.input.SAXBuilder;
import org.jdom.*;

public class XPDLParser {
	private Document doc;
	public XPDLParser(String fileName){
		SAXBuilder saxBuilder = new SAXBuilder(false);
		doc = null;
		try {
			doc = saxBuilder.build(new FileInputStream(new File(fileName)));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public Element[] getElements(String elementName){
		Element root = doc.getRootElement();
		Element[] temMetas = ElementUtils.findElements(root,elementName,null, null, null);
		return temMetas;
	}
	
	public static void main(String[] args) {
		String fileName = "XmlParser.xml";
		XPDLParser xp =new XPDLParser("src\\parse\\xml\\"+fileName);
		Element[] nodes=xp.getElements("gg");
		for (int i = 0; i < nodes.length; i++) {
			System.out.println(nodes[i].getText());
		}
	}

}
